package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class Test {
    public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection()) {
            conn.setAutoCommit(false);//关闭主动提交
            String sql = "UPDATE teacher " +
                         "SET salary = salary + 500 " +
                         "WHERE subject_id =(SELECT id FROM subject WHERE name='语文')";
            Statement  ps  = conn.createStatement();
        int num = ps.executeUpdate(sql);
            System.out.println(num>0?"添加成功":"添加失败");
            conn.commit();
            System.out.println("添加成功了");
                /*conn.rollback();
                System.out.println("事务回滚了");*/
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
